﻿$(document).ready(function () {
    var J_pop_saling = $("#J_pop_saling");
    var J_light_del = $("#J_light_del");
    //修正ie6下弹层不加载背景图问题 先显示弹层 放在屏幕范围外 再js隐藏
    J_light_del.removeClass("light-del");

    //日期选择
    $("#J_createDateBegin").bind("focus click", function () {
        return WdatePicker({ lang: 'zh-cn', dateFmt: 'yyyy-MM-dd', minDate: '2010-01-01', maxDate: '%y-%M-%d' });
    }).attr("readonly", "true");
    $("#J_createDateEnd").bind("focus click", function () {
        var minDate = $("#J_createDateBegin").val();
        return WdatePicker({ lang: 'zh-cn', dateFmt: 'yyyy-MM-dd', minDate: minDate, maxDate: '%y-%M-%d' });
    }).attr("readonly", "true");

    //超出字符

    //下架
    $("#J_tablelist").find(".exec-cancel").mouseover(function () {
        var t = $(this);
        J_pop_saling.show().css({ top: t.offset().top + t.height(), left: t.offset().left - J_pop_saling.width() + t.width() });
    });
    J_pop_saling.find(".pop-close").click(function () {
        J_pop_saling.hide();
    });

    //删除
    $("#J_tablelist").find(".exec-del").click(function () {
        var t = $(this);
        J_light_del.show();
        J_light_del.find(".light-bg").css("height", $(document).height());
        J_light_del.find(".light-box").css({ left: (t.offset().left - J_light_del.find(".light-box").width() - 100), top: (t.offset().top - J_light_del.find(".light-box").height() / 2) });
        J_light_del.find(".light-iframe").css("height", $(document).height());
        J_light_del.find(".light-btn-confirm").attr("href", t.attr("href"));
        return false;
    });
    J_light_del.find(".light-close").click(function () {
        J_light_del.hide();
    });

    //查看优惠券
    var J_light_view = $("#J_light_view");
    $("#J_tablelist").find(".exec-view").click(function () {
        var t = $(this);
        J_light_view.show();
        J_light_view.find(".light-bg").css("height", $(document).height());
        J_light_view.find(".light-iframe").css("height", $(document).height());
        J_light_view.find(".light-btn-confirm").attr("href", t.attr("data-href"));
        J_light_view.find(".light-iframe-view").attr("src", t.attr("href"));
        J_light_view.find(".light-box").css({ left: (t.offset().left - J_light_view.find(".light-box").width() - 100), top: (t.offset().top - J_light_view.find(".light-box").height() / 2) });
        return false;
    });
    J_light_view.find(".light-close, .light-btn-close").click(function () {
        J_light_view.hide();
    }).attr("href","javascript:void(0)");
});

//old
function setQueryType(status) {
    var obj = document.getElementById('queryStatus');
    for (i = 0; i < obj.length; i++) {
        if (obj.options[i].value == status) {
            obj.options[i].selected = true;
            break;
        }
    }
    document.getElementsByName('queryOrderForm')[0].submit();
}
function gotoPage(page) {
    var form = document.getElementById("queryOrderForm");
    var currentPage = document.getElementById("currentPage");
    currentPage.value = page;
    form.submit();
}
function gotoPageByNum() {
    var form = document.getElementById("queryOrderForm");
    var currentPage = document.getElementById("currentPage");
    var gopagenum = document.getElementById("gopagenum");
    currentPage.value = gopagenum.value;
    form.submit();
}
function checkInput() {
    var searchinput = document.getElementById("J_searchinput").value;
    //alert("searchinput=" + searchinput);	
    var tmp = toTXT(searchinput);
    //alert(searchinput + "----" + tmp);
    if (tmp != searchinput) return false;
}

function toTXT(str) {
    var RexStr = /\<|\>|\"|\'|\&/g
    str = str.replace(RexStr,
         function (MatchStr) {
             switch (MatchStr) {
                 case "<":
                     return "& lt;";
                     break;
                 case ">":
                     return "& gt;";
                     break;
                 case "\"":
                     return "& quot;";
                     break;
                 case "'":
                     return "& #39;";
                     break;
                 case "&":
                     return "& amp;";
                     break;
                 default:
                     break;
             }
         }
     )
    return str;
}

function inputSuitNum(totalPage) {
    var gopagenum = document.getElementById("gopagenum");
    gopagenum.value = gopagenum.value.replace(/[^\d]/g, '');
    if (gopagenum.value > totalPage || gopagenum.value < 1) {
        gopagenum.value = "";
    }
}